package de.ipcas.colorPicker;

import com.summarecon.qualitycontrol.R;
import com.summarecon.singleton.ColorPicker;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

public class ColorPickerDialog extends Dialog {
	
	public ColorPickerDialog(Context context) {
		super(context);
		this.setTitle("ColorPicker");
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.color_picker);

		final GridView gridViewColors = (GridView) findViewById(R.id.gridViewColors);
		gridViewColors.setAdapter(new ColorPickerAdapter(getContext()));

		// close the dialog on item click
		gridViewColors.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				ColorPickerDialog.this.dismiss();
				//ColorPicker.setColor(id);
				//String hexColor1 = String.format("#%06X", (0xFFFFFF & (int) parent.getAdapter().getItemId(position)));
				ColorPicker.setColor((int) parent.getAdapter().getItemId(position));
				//Log.i("COLOR", ""+ Integer.parseInt(hexColor1.replaceFirst("#", ""), 16));
			}
		});

	}
	
}
